package javagame;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Play extends BasicGameState{
	
	Animation Sora, movingUp, movingDown, movingLeft, movingRight, Stand, Back;
	Image map1;
	boolean quit = false;
	float soraPositionX = 0;
	float soraPositionY = 0;
	int[] duration = {100,100,100,100,100,100,100,100};
	int[] duration1 = {100,100,100,100,100,100};
	float shiftX = soraPositionX + 300;
	float shiftY = soraPositionY + 200;
	
	public Play(int state){
	}
	
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
		map1 = new Image("res/battleback.jpg");
		Image[] walkUp = {new Image("res/Sora/SoraBack0.png"), new Image("res/Sora/SoraBack1.png"),
				new Image("res/Sora/SoraBack2.png"), new Image("res/Sora/SoraBack3.png"), new Image("res/Sora/SoraBack4.png"),
				new Image("res/Sora/SoraBack5.png"), new Image("res/Sora/SoraBack6.png"), new Image("res/Sora/SoraBack7.png")};
		Image[] walkDown = {new Image("res/Sora/SoraFront0.png"), new Image("res/Sora/SoraFront1.png"),
				new Image("res/Sora/SoraFront2.png"), new Image("res/Sora/SoraFront3.png"), new Image("res/Sora/SoraFront4.png"),
				new Image("res/Sora/SoraFront5.png"), new Image("res/Sora/SoraFront6.png"), new Image("res/Sora/SoraFront7.png")};		
		Image[] walkLeft = {new Image("res/Sora/SoraLeft0.png"), new Image("res/Sora/SoraLeft1.png"),
				new Image("res/Sora/SoraLeft2.png"), new Image("res/Sora/SoraLeft3.png"), new Image("res/Sora/SoraLeft4.png"),
				new Image("res/Sora/SoraLeft5.png")};
		Image[] walkRight = {new Image("res/Sora/SoraRight0.png"), new Image("res/Sora/SoraRight1.png"),
				new Image("res/Sora/SoraRight2.png"), new Image("res/Sora/SoraRight3.png"), new Image("res/Sora/SoraRight4.png"),
				new Image("res/Sora/SoraRight5.png"),};
		Image[] Front = {new Image("res/Sora/SoraFront.png"), new Image("res/Sora/SoraFront.png")};
		Image[] Backs = {new Image("res/Sora/SoraBack.png"), new Image("res/Sora/SoraBack.png")};
		
				
		movingUp = new Animation(walkUp, duration, false);
		movingDown = new Animation(walkDown, duration, false);
		movingLeft = new Animation(walkLeft, duration1, false);
		movingRight = new Animation(walkRight, duration1, false);
		Sora = new Animation(Front,100);
		Stand = new Animation(Front,100);
		Back = new Animation(Backs,100);
		
	}
	
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
		map1.draw(soraPositionX,soraPositionY);
		Sora.draw(shiftX,shiftY);
		g.drawString("Sora X:"+soraPositionX+ "\nSora Y:"+soraPositionY, 400,100);
		
		if(quit==true){
			g.drawString("Resume (Enter)", 500, 300);
			g.drawString("Main Menu (BackSpace)", 550, 350);
			g.drawString("Quit Game (Esc)", 600, 400);
			if(quit==false){
				g.clear();
			}
		}
	}

	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
		Input input = gc.getInput();
		if(input.isKeyDown(Input.KEY_UP)){
			Sora = movingUp;
			soraPositionY += delta *.1f;
			System.out.println("Up Key is Press");
			} else {
				Sora = Stand; 
			}
		if(input.isKeyDown(Input.KEY_DOWN)){
			Sora = movingDown;
			soraPositionY -= delta *.1f;
			System.out.println("Down Key is Press");
			} else {
				
			}
		if(input.isKeyDown(Input.KEY_LEFT)){
				Sora = movingLeft;
				soraPositionX += delta *.1f;
				System.out.println("Left Key is Press");
			}
		if(input.isKeyDown(Input.KEY_RIGHT)){
				Sora = movingRight;
				soraPositionX -= delta *.1f;
				System.out.println("Right Key is Press");
			}
		Sora.update(delta);
		
	}
	public int getID(){
		return 1;
	}
}
